package com.haisen.service.impl;

import com.haisen.dataobject.entity.Dic;
import com.haisen.dataobject.mapper.base.DicMapper;
import com.haisen.service.DicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.weekend.Weekend;
import tk.mybatis.mapper.weekend.WeekendCriteria;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DicServiceImpl implements DicService {

    @Autowired
    private DicMapper dicMapper;

    @Override
    public Map<String, String> GetDic(String tableName, String fieldName) {
        Weekend<Dic> example = Weekend.of(Dic.class);
        WeekendCriteria<Dic,Object> weekendCriteria = example.weekendCriteria();
        weekendCriteria.andEqualTo(Dic::getTableName,tableName);
        weekendCriteria.andEqualTo(Dic::getFieldName,fieldName);
        List<Dic> dicList = dicMapper.selectByExample(example);
        Map<String,String> dicMap = new HashMap<>();
        dicList.stream().map( o -> {
           dicMap.put(o.getFieldValue(),o.getFieldDetail());
           return dicMap;
        }).collect(Collectors.toList());
        return dicMap;
    }


}
